<?php

namespace App\Models\Traits;

trait HasUserGoldCharge
{
	public function hasValidGoldCharge()
	{
		return $this->goldCharges()->whereNotNull('paid_at')->exists();
	}
	
	public function hasNoValidGoldCharge()
	{
		return !$this->hasValidGoldCharge();
	}
	
	public function isLowestChargeEnough()
	{
		$totalAmount = $this->goldCharges()->whereNotNull('paid_at')->sum('total_amount');
		return big_decimal($totalAmount)->isGreaterThanOrEqualTo(80);
	}
	
	public function isLowestChargeNotEnough()
	{
		return !$this->isLowestChargeEnough();
	}
	
	public function goldChargeTotalAmount()
	{
		return $this->goldCharges()->whereNotNull('paid_at')->sum('total_amount');
	}

}
